package com.cheer.ba.view.activity;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.cheer.ba.R;
import com.cheer.ba.constant.IntentKey;
import com.cheer.ba.model.LookMyBillModel;
import com.cheer.ba.utils.Currency;
import com.cheer.ba.utils.ImageUtils;
import com.cheer.ba.utils.Protect;
import com.cheer.ba.utils.StringUtils;
import com.cheer.ba.utils.TextViewUtils;
import com.cheer.ba.view.base.BaseCommAty;

import butterknife.BindView;

/**
 * 描述 ：记账详情
 * 作者 ：hq
 * 时间 ：2017/5/24 12:43
 */
public class DetailBooksAty extends BaseCommAty {

    @BindView(R.id.id_book_type_img)
    ImageView mImgType;
    @BindView(R.id.id_detail_img)
    ImageView mImgPic;

    @BindView(R.id.id_detail_money_txt)
    TextView mTxtMoney;
    @BindView(R.id.id_detail_time_txt)
    TextView mTxtTime;
    @BindView(R.id.id_detail_title_txt)
    TextView mTxtTitle;
    @BindView(R.id.id_detail_content_txt)
    TextView mTxtContent;

    private LookMyBillModel model;

    @Override
    public View loadView(LayoutInflater inflater, View childView) {
        return super.loadView(inflater, inflater.inflate(R.layout.aty_detail_books, null, false));
    }

    @Override
    public void initView() {
        setTitleText("账单详情");
        model = (LookMyBillModel) getIntent().getSerializableExtra(IntentKey.General.KEY_MODEL);
        if (null != model) {
            String money = Currency.returnDollar(model.money);
            if (model.logType == 1) {
                //进账
                mImgType.setImageResource(R.drawable.ic_incream);
                if (model.accountType == 1) {
                    money = "个人支入    +" + money;
                } else {
                    money = "企业支入    +" + money;
                }
                TextViewUtils.setSpannableStyleColor(money, 8, money.length() - 1, mTxtMoney, R.color.color_main);
            } else {
                //出账
                mImgType.setImageResource(R.drawable.ic_outcream);
                if (model.accountType == 1) {
                    money = "个人支出    -" + money;
                } else {
                    money = "企业支出    -" + money;
                }
                TextViewUtils.setSpannableStyleColor(money, 0, money.length() - 1, mTxtMoney, R.color.color_333333);
            }
            mTxtTime.setText(StringUtils.getDetailStr1(model.createTime));
            mTxtTitle.setText(model.name);
            mTxtContent.setText(model.remark);
            if (StringUtils.isEmpty(model.attachmentUrl1) && StringUtils.isEmpty(model.attachmentUrl2)) {
                mImgPic.setVisibility(View.GONE);
            } else {
                mImgPic.setVisibility(View.VISIBLE);
                String pic = StringUtils.isEmpty(model.attachmentUrl1) ? Protect.setPic(model.attachmentUrl2) : Protect.setPic(model.attachmentUrl1);
                ImageUtils.showRoundImg(aty, pic, R.drawable.ic_bg_default_book, R.drawable.ic_bg_default_book, mImgPic);
            }
        } else {
            dataStatus(2);
        }
    }
}
